using UnityEngine;
using System.Collections;

public class DanceMode : MonoBehaviour {
	
	public float speed;
	float min;
	float max;
	bool isY;
	wrapMode mode;
	
	void Start()
	{
		
		int i = Random.Range(0,2);
		
		if(i == 0)
		{
			isY = false;
			min = transform.position.x - 0.5f;
			max = transform.position.x + 0.5f;
		}
		else
		{
			isY = true;
			min = transform.position.y - 0.5f;
			max = transform.position.y + 0.5f;
		}
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(isY)
		{
			if(mode == wrapMode.RIGHT)
			{
				float move = transform.position.y + (speed*Time.deltaTime);
				transform.position = new Vector3(transform.position.x,move,transform.position.z);
			}
			else
			{
				float move = transform.position.y - (speed*Time.deltaTime);
				transform.position = new Vector3(transform.position.x,move,transform.position.z);			
			}
						
			if(transform.position.y >= max && mode == wrapMode.RIGHT)
			{
				mode = wrapMode.LEFT;
			}
			if(transform.position.y <= min && mode == wrapMode.LEFT)
			{
				mode = wrapMode.RIGHT;
			}
		}
		else
		{
			if(mode == wrapMode.RIGHT)
			{
				float move = transform.position.x + (speed*Time.deltaTime);
				transform.position = new Vector3(move,transform.position.y,transform.position.z);
			}
			else
			{
				float move = transform.position.x - (speed*Time.deltaTime);
				transform.position = new Vector3(move,transform.position.y,transform.position.z);
			}
			
			if(transform.position.x >= max && mode == wrapMode.RIGHT)
			{
				mode = wrapMode.LEFT;
			}
			if(transform.position.x <= min && mode == wrapMode.LEFT)
			{
				mode = wrapMode.RIGHT;
			}

		}
	}
	
	public enum wrapMode
	{
		LEFT,
		RIGHT
	}
}
